package de.digiway.rapidbreeze.client;

import de.digiway.rapidbreeze.client.infrastructure.I18n;
import de.digiway.rapidbreeze.client.controller.ClientController;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

/**
 * Main class for Java FX Application.
 *
 * @author Sigurd
 */
public class RapidBreezeClient extends Application {

    private static final String FXML = "/fxml/ClientView.fxml";
    private static final String WINDOW_TITLE = "Rapid Breeze";

    public static void main(String[] args) throws Exception {
        launch(args);
    }

    @Override
    public void start(Stage stage) throws Exception {
        URL url = getClass().getResource(FXML);
        ResourceBundle resourceBundle = I18n.getInstance().getResourceBundle();
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(url);
        loader.setResources(resourceBundle);

        Parent rootNode;
        try (InputStream is = url.openStream()) {
            rootNode = (Parent) loader.load(is);
        } catch (IOException ex) {
            throw new IllegalStateException("Cannot load FXML file.", ex);
        }

        ClientController clientController = loader.getController();
        clientController.setParentStage(stage);

        Scene scene = new Scene(rootNode);
        stage.setTitle(WINDOW_TITLE);
        stage.setScene(scene);

        stage.show();
    }
}
